//
//  HotMovieCell.m
//  MyMovie
//
//  Created by Weiwei on 16/3/2.
//  Copyright © 2016年 bever贝沃汇力 weiwei. All rights reserved.
//

#import "HotMovieCell.h"

@implementation HotMovieCell

- (void)awakeFromNib {
    // Initialization code
}


#pragma -mark 重写setModel对自己的属性复制
-(void)setHotMovieModel:(HotMovieModel *)hotMovieModel{
    
    _hotMovieModel = hotMovieModel;
    
//加载图片
    [self.movieImag setImageWithURL:[NSURL URLWithString:_hotMovieModel.img]];
//电影名
    self.movieTitle.text = _hotMovieModel.tCn;
    

    
//日期设置 "20150619",
    NSString* date = _hotMovieModel.rd;
    // 06 19
    NSString* moth = [date substringWithRange:NSMakeRange(4, 2)];
    NSString* day = [date substringWithRange:NSMakeRange(6, 2)];
    self.movieDate.text = [NSString stringWithFormat:@"%@月%@日上映",moth,day];
    
    
//有多少家影院上映
    self.movieCinema.text = [NSString stringWithFormat:@"今日有%@家影院 %@场",_hotMovieModel.NearestCinemaCount,_hotMovieModel.NearestShowtimeCount];
    
    //-----------给cell添加image------------
    
    //    "isIMAX": false,
    //    "isIMAX3D": true,
    //    "isDMAX": true,
    
    //img:
    //    icon_hot_show_DMAX 巨幕图片
    //    icon_hot_show_IMAX3D
    //    icon_hot_show_IMAX
    
    
    //(1)创建一个字典，用来接受存在的图片字符串
    NSMutableDictionary* _imagDic = [[NSMutableDictionary alloc]initWithCapacity:1];
    
    //(2)判断图片存不存在
    if ([_hotMovieModel.isIMAX intValue]==1) {
        [_imagDic setObject:@"icon_hot_show_IMAX" forKey:@"isIMAX"];
    }
    if ([_hotMovieModel.isIMAX3D intValue] == 1) {
        [_imagDic setObject:@"icon_hot_show_IMAX3D" forKey:@"isIMAX3D"];
    }
    if ([_hotMovieModel.isDMAX intValue] == 1) {
        [_imagDic setObject:@"icon_hot_show_DMAX" forKey:@"isDMAX"];
        
    }
    
    //4移除复用的影响
    for (UIView* subView in self.contentView.subviews) {
        
        if (subView.frame.size.width == 40) {
            [subView removeFromSuperview];
        }
        
        
        
    }
    
    
    
    
    
    
    //3根据存在的数据，创建相对应的imageView
    NSArray* key = [_imagDic allKeys];
    for (int i =0; i < key.count; i++) {
        
        UIImageView* imageView = [[UIImageView alloc]initWithFrame:CGRectMake(104+ i*(40+5), 90, 40, 20)];
        imageView.image = [UIImage imageNamed:[_imagDic objectForKey:key[i]]];
        
        [self.contentView addSubview:imageView];
        
        
    }
    
  //-----------优化评分----------------
    //设置评分
//    self.movieRating.text = [NSString stringWithFormat:@"%.1f",[_hotMovieModel.r floatValue]];
    
    //1.获取当前json评分数据
    float rating =[_hotMovieModel.r floatValue];
    if (rating < 0) {
        rating = 0;
    }
    
    //2.富文本---带有属性的字符串
    NSMutableAttributedString* maString =[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%.1f",rating]];
    //3.为属性字符串设置属性
    //为属性字符串增加一个属性  属性名  属性值 范围值
    [maString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(2, 1)];
    
    //4.给lable复制
    self.movieRating.attributedText = maString;
    
    //---------优化评论------------
//    //评论
//    self.movieComment.text = _hotMovieModel.commonSpecial;
    
    if ([_hotMovieModel.commonSpecial isEqualToString:@""]) {
        
     //0.获得期待的人数
        NSString* wanted = [NSString stringWithFormat:@"%ld",[_hotMovieModel.wantedCount integerValue]];
        
        
     //1.创建一个正常的字符串
        NSString* string = [NSString stringWithFormat:@"%@人期待观看",wanted];
        
     //3.创建一个富文本字符串
        NSMutableAttributedString* wantmaString = [[NSMutableAttributedString alloc]initWithString:string];
        
        
     //4.加属性
        [wantmaString addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, wanted.length)];
        
        
        self.movieComment.attributedText = wantmaString;
        
        
        
    }else{
    
        self.movieComment.text = _hotMovieModel.commonSpecial;
        
    }

    
    
    
    
}











- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
